<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>错误 - 学生信息管理系统</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div class="container">
        <div class="error-page">
            <h1>404</h1>
            <h2>页面未找到</h2>
            <p>抱歉，您访问的页面不存在或已被移除。</p>
            
            <% if (request.getAttribute("errorCode") != null) { %>
                <div class="message error">
                    错误代码: <%= request.getAttribute("errorCode") %>
                </div>
            <% } %>
            
            <% if (request.getAttribute("errorMessage") != null) { %>
                <div class="message error">
                    错误信息: <%= request.getAttribute("errorMessage") %>
                </div>
            <% } %>
            
            <div class="btn-group">
                <a href="javascript:history.back()" class="btn btn-secondary">返回上一页</a>
                <a href="index.jsp" class="btn btn-primary">返回首页</a>
            </div>
        </div>
    </div>
    
    <script src="js/script.js"></script>
    <script>
        // 根据不同的错误代码显示不同的内容
        const errorCode = new URLSearchParams(window.location.search).get('code');
        if (errorCode) {
            const errorTitle = document.querySelector('.error-page h2');
            const errorDesc = document.querySelector('.error-page p');
            const errorCodeElement = document.querySelector('.error-page h1');
            
            switch(errorCode) {
                case '401':
                    errorCodeElement.textContent = '401';
                    errorTitle.textContent = '未授权访问';
                    errorDesc.textContent = '您没有权限访问此页面，请先登录。';
                    break;
                case '403':
                    errorCodeElement.textContent = '403';
                    errorTitle.textContent = '禁止访问';
                    errorDesc.textContent = '您没有权限执行此操作。';
                    break;
                case '404':
                    // 默认已设置
                    break;
                case '500':
                    errorCodeElement.textContent = '500';
                    errorTitle.textContent = '服务器错误';
                    errorDesc.textContent = '服务器内部错误，请稍后重试。';
                    break;
                default:
                    errorTitle.textContent = '发生错误';
                    errorDesc.textContent = '系统遇到了一个问题，请稍后重试。';
            }
        }
    </script>
</body>
</html>